<?php
/**
 * Created by PhpStorm.
 * User: Cloud
 * Date: 2018/5/14
 * Time: 13:23
 */
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <!--[if lt IE 7]>
    <div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
                                                                               href="http://browsehappy.com">立即升级</a>
    </div>
    <![endif]-->
    <meta charset="UTF-8">
    <title>详细统计</title>
    <meta name="description"
          content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
    <meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
    <meta name="copyright" content="上海易推信息科技有限公司"/>
    <meta name="renderer" content="webkit">
    <base href="<?php echo base_url(); ?>"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="public/js/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="public/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/cost-center.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/popup.css"/>
    <link rel="stylesheet" href="public/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="public/css/bootstrap.css">
    <link rel="stylesheet" href="public/css/dcalendar.picker.css">
    <link rel="stylesheet" href="public/css/paging.css">
    <link rel="stylesheet" href="public/css/cqs.style.css">
    <!--[if lte IE 9]>
    <script type="text/javascript" src="public/js/html5shiv-printshiv-3.js"></script>
    <![endif]-->

    <style type="text/css">
        * {
            -webkit-box-sizing: unset;
            -moz-box-sizing: unset;
            box-sizing: unset;
        }

        dt, dd {
            line-height: unset;
        }

        .month {
            word-break: keep-all;
        }

        .box .pageWrap ul li {
            width: 59px;
        }

        caption {
            display: none;
        }

        .button-default {
            display: none;
        }

        .cqs-output:hover {
            text-decoration: none;
            color: white;
        }
    </style>

</head>
<body style="background-color: #f4f4f4;">
<?php $this->load->view('common/header.php'); ?>

<div class="cqs-main">
    <form method="get" id="data-form">
        <div class="cqs-main_top cqs-mgt30">
            数据报表：<a class="cqs-clc40000" href="<?php echo base_url('information/information_purchase_user'); ?>">成本中心＞采购用户</a>

            <div class="date-box">
                <!--            // --><?php //if ( isset($ymd)):?><!--  value="-->
                <?php //echo $ymd ;?><!--"  --><?php //endif;?>
                <span class="date-group"><input id='mydatepicker'
                                                name="mydatepicker" <?php if (isset($ymd)): ?> value="<?php echo $ymd; ?>" placeholder="<?php echo $ymd; ?>"  <?php endif; ?>
                                                type='text'/>
                    <!--        <img src="--><?php //echo base_url(); ?><!--public/img/btn_arrow_down_h.png" alt="">-->
                </span> —
                <span class="date-group">
                <input id='mydatepicker2' <?php if (isset($ymd2)): ?> value="<?php echo $ymd2; ?>"  placeholder="<?php echo $ymd2; ?>" <?php endif; ?>
                       type='text'/>
                <input type="hidden" name="mydatepicker2" class="mydatepicker2" type='text' value=""/>
                    <!--        <img src="--><?php //echo base_url(); ?><!--public/img/btn_arrow_down_h.png" alt="">-->
                </span>
            </div>

            <div class="cqs-search-group"><span class="cqs-img-search">
                <img src="<?php echo base_url(); ?>public/img/icon_search_grey.png" alt=""></span>
                <input class="form-control" type="text" id="username" name="username"
                       placeholder="在当前条件下搜索账户" <?php if (isset($username)): ?> value="<?php echo $username; ?>"  <?php endif; ?>>
            </div>

            <div class="checkbox-group"><label for="account"><input type="checkbox" name="account"
                                                                    id="account" <?php if (isset($account) && $account == 2): ?> value="" checked  <?php else: ?> value="2"  <?php endif; ?> >管理账户</label>
            </div>
            <div class="checkbox-group"><label for="user"><input type="checkbox" name="user"
                                                                 id="user" <?php if (isset($user) && $user == 3): ?> value="" checked  <?php else: ?> value="3"   <?php endif; ?> >用户账号</label>
            </div>
            <button type="submit" style="display: none"></button>
            <a style="float: right; margin-right: 20px;margin-top:19px;" class="cqs-output">导出报表</a>
        </div>
    </form>
    <table class="" id="table" style="display: none">
        <tr>
            <th>序号</th>
            <th>账号</th>
            <th>所属成本中心</th>
            <?php if (isset($time6)): ?>
                <th class="tableexport-string target"><?php echo $time6 ?></th>
            <?php endif; ?>
            <?php if (isset($time5)): ?>
                <th class="tableexport-string target"><?php echo $time5 ?></th>
            <?php endif; ?>
            <?php if (isset($time4)): ?>
                <th class="tableexport-string target"><?php echo $time4 ?></th>
            <?php endif; ?>
            <?php if (isset($time3)): ?>
                <th class="tableexport-string target"><?php echo $time3 ?></th>
            <?php endif; ?>
            <?php if (isset($time2)): ?>
                <th class="tableexport-string target"><?php echo $time2 ?></th>
            <?php endif; ?>
            <?php if (isset($time1)): ?>
                <th class="tableexport-string target"><?php echo $time1 ?></th>
            <?php endif; ?>
            <th>合计(元)</th>
        </tr>
        <tbody>
        </tbody>
    </table>

    <div class="cqs-main_con table-responsive cqs-box cqs-mgb50 cqs-bgfff"><!--table table-bordered -->
        <table class="table table-bordered cqs-table">
            <tr>
                <th>序号</th>
                <th>账号</th>
                <th>所属成本中心</th>
                <?php if (isset($time6)): ?>
                    <th class="tableexport-string target"><?php echo $time6 ?></th>
                <?php endif; ?>
                <?php if (isset($time5)): ?>
                    <th class="tableexport-string target"><?php echo $time5 ?></th>
                <?php endif; ?>
                <?php if (isset($time4)): ?>
                    <th class="tableexport-string target"><?php echo $time4 ?></th>
                <?php endif; ?>
                <?php if (isset($time3)): ?>
                    <th class="tableexport-string target"><?php echo $time3 ?></th>
                <?php endif; ?>
                <?php if (isset($time2)): ?>
                    <th class="tableexport-string target"><?php echo $time2 ?></th>
                <?php endif; ?>
                <?php if (isset($time1)): ?>
                    <th class="tableexport-string target"><?php echo $time1 ?></th>
                <?php endif; ?>
                <th>合计(元)</th>
            </tr>
            <tbody>
            </tbody>
        </table>

        <div class="box" id="box"></div>
    </div>
</div>
<?php $this->load->view('common/bottom.php'); ?>

<script src="public/js/jquery.min.js"></script>
<script src="public/js/bootstrap-table.min.js"></script>
<script src="public/js/paging.min.js"></script>
<script type="text/javascript" src="public/js/jquery.query-object.js" charset="utf-8"></script>
<script src="public/js/dcalendar.picker.user.js"></script>


<script type="text/javascript" src="public/js/xlsx.core.min.js"></script>
<script type="text/javascript" src="public/js/FileSaver.js"></script>
<script type="text/javascript" src="public/js/jquery.table2excel.js"></script>

<script>


    $('.button-default').hide();

    $('.cqs-output').on('click', function (event) {

        var ie = (function () {

            var undef,
                v = 3,
                div = document.createElement('div'),
                all = div.getElementsByTagName('i');

            while (
                div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
                    all[0]
                ) ;

            return v > 4 ? v : undef;

        }());
        if ((typeof(ie) == 'undefined') == true) {

            var account = $('#account').val();
            var user = $('#user').val();
            var username = $('#username').val();
            var ymd = $('#mydatepicker').attr('placeholder');
            var ymd2 = $('#mydatepicker2').attr('placeholder');
            console.log(ymd2);
            console.log(ymd);
            //location.href="<?php //echo base_url()?>//information/information_purchase_user?page="+page;
            $.ajax({
                type: "post",
                url: "information/information_purchase_user",
                data: {
                    page: 1,
                    row: 1,
                    account: account,
                    user: user,
                    ymd: ymd,
                    ymd2: ymd2,
                    username: username
                },
                dataType: "json",
                async: true,
                success: function (data) {
                    var html = "";
                    // console.log(data);
                    $(data.data).each(function (key, val) {
                        // console.log(val);
                        html += "  <tr class='attr'>";

                        html += "  <td>" + (key + 1) + "</td>";

                        html += "  <td>" + val.username + "</td>";
                        html += "  <td>" + val.name + "</td>";
                        if (!val.money1) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money1 + "</td>";
                        }
                        if (!val.money2) {
                            html += "  <td>0</td>";
                        } else {

                            html += "  <td>" + val.money2 + "</td>";
                        }

                        if (!val.money3) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money3 + "</td>";

                        }
                        if (!val.money4) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money4 + "</td>";

                        }
                        if (!val.money5) {
                            html += "  <td>0</td>";
                        } else {

                            html += "  <td>" + val.money5 + "</td>";
                        }
                        if (!val.money6) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money6 + "</td>";
                        }
                        if (!val.moneys) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.moneys + "</td>";
                        }

                        html += " </tr>";
                    });
                    $("#table tbody:last").html(html);

                    var DefaultTable = document.getElementById('table');
                    var table = new TableExport(DefaultTable, {
                        headers: true,                              // (Boolean), display table headers (th or td elements) in the <thead>, (default: true)
                        footers: true,                              // (Boolean), display table footers (th or td elements) in the <tfoot>, (default: false)
                        formats: ['xlsx'],                          // (String[]), filetype(s) for the export, (default: ['xlsx', 'csv', 'txt'])
                        filename: '数据报表-用户采购统计',                             // (id, String), filename for the downloaded file, (default: 'id')
                        bootstrap: false,                           // (Boolean), style buttons using bootstrap, (default: false)
                        exportButtons: true,
                        position: 'bottom',                         // (top, bottom), position of the caption element relative to table, (default: 'bottom')
                        ignoreRows: null,                           // (Number, Number[]), row indices to exclude from the exported file(s) (default: null)
                        ignoreCols: null,                           // (Number, Number[]), column indices to exclude from the exported file(s) (default: null)
                        ignoreCSS: '.tableexport-ignore',           // (selector, selector[]), selector(s) to exclude cells from the exported file(s) (default: '.tableexport-ignore')
                        emptyCSS: '.tableexport-empty',             // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file(s) (default: '.tableexport-empty')
                        trimWhitespace: false                        // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: true)
                    });

                    $('.button-default').trigger('click')

                }
            });
        } else {
            layer.alert('浏览器版本过低，请更新您的浏览器或使用其他浏览器导出报表');
        }
        event.stopPropagation();
        return false

    })


    var setTotalCount = 301;
    $('#box').paging({
        initPageNo: 1, // 初始页码
        totalPages: <?php echo ceil(count($orders) / 10) ?>, //总页数
        totalCount: '', // 条目总数
        slideSpeed: 600, // 缓动速度。单位毫秒
        jump: true, //是否支持跳转
        callback: function (page) { // 回调函数
            // console.log(page);
            // var admin = $('#admin').val();
            var account = $('#account').val();
            var user = $('#user').val();
            var username = $('#username').val();
            var ymd = $('#mydatepicker').attr('placeholder');
            var ymd2 = $('#mydatepicker2').attr('placeholder');
            console.log(ymd2);
            console.log(ymd);
            //location.href="<?php //echo base_url()?>//information/information_purchase_user?page="+page;
            $.ajax({
                type: "post",
                url: "information/information_purchase_user",
                data: {
                    page: page,
                    // admin: admin,
                    account: account,
                    user: user,
                    ymd: ymd,
                    ymd2: ymd2,
                    username: username
                },
                dataType: "json",
                async: true,
                success: function (data) {
                    var html = "";
                    // console.log(data);
                    $(data.data).each(function (key, val) {
                        // console.log(val);
                        html += "  <tr class='attr'>";

                        html += "  <td>" + (key + 1) + "</td>";

                        html += "  <td><a href='<?php echo base_url('information/detail');?>?uid=" + val.id + "'>" + val.username + "</a></td>";
                        html += "  <td>" + val.name + "</td>";
                        if (!val.money1) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money1 + "</td>";
                        }
                        if (!val.money2) {
                            html += "  <td>0</td>";
                        } else {

                            html += "  <td>" + val.money2 + "</td>";
                        }

                        if (!val.money3) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money3 + "</td>";

                        }
                        if (!val.money4) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money4 + "</td>";

                        }
                        if (!val.money5) {
                            html += "  <td>0</td>";
                        } else {

                            html += "  <td>" + val.money5 + "</td>";
                        }
                        if (!val.money6) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.money6 + "</td>";
                        }
                        if (!val.moneys) {
                            html += "  <td>0</td>";
                        } else {
                            html += "  <td>" + val.moneys + "</td>";
                        }

                        html += " </tr>";
                    });
                    $(".table tbody:last").html(html);

                    // console.log(html);
                }
            });

        }
    });

    var _date = new Date();
    $('#mydatepicker').dcalendarpicker({
        format: 'yyyy-mm',
        // defaultDate: '1',
        // changeYear: true,
        // viewMode: 'months'
    }).on('dateselected', function (e) {
        $('#mydatepicker').val(e.date.getFullYear() + '-' + ("0" + (e.date.getMonth() + 1)).slice(-2)).trigger('onchange')
        var e_text = e.date.getFullYear() + '-' + ("0" + (e.date.getMonth() + 1)).slice(-2);
        var s = e.date;
        s.setMonth(s.getMonth() + 5);
        goUrl(e_text, s.getFullYear() + '-' + ("0" + (s.getMonth() + 1)).slice(-2));
        // window.location.search = jQuery.query
        //     .set("mydatepicker", e_text)
        //     .set("mydatepicker2", s.getFullYear() + '-' + ("0" + (s.getMonth() + 1)).slice(-2));
    });

    $('#mydatepicker2').dcalendarpicker({
        format: 'yyyy-mm',
        // defaultDate: '1',
        // changeYear: true,
        // viewMode: 'months'
    }).on('dateselected', function (e) {
        $('#mydatepicker2').val(e.date.getFullYear() + '-' + ("0" + (e.date.getMonth() + 1)).slice(-2)).trigger('onchange')
        var e_text = e.date.getFullYear() + '-' + ("0" + (e.date.getMonth() + 1)).slice(-2);
        var s = e.date;
        s.setMonth(s.getMonth() - 5);
        goUrl(s.getFullYear() + '-' + ("0" + (s.getMonth() + 1)).slice(-2), e_text);
        // window.location.search = jQuery.query
        //     .set("mydatepicker", s.getFullYear() + '-' + ("0" + (s.getMonth() + 1)).slice(-2))
        //     .set("mydatepicker2", e_text);
    });

</script>
<script type="text/javascript">
    $('#account').click(function () {
        var accounts = $('#account').attr('checked');
        if (!accounts) {
            $('#account').val('2');
        } else {
            $('#account').val("");
        }
        var users = $('#user').attr('checked');
        if (!users) {
            $('#user').val('3');
        } else {
            $('#user').val("");
        }
        //var admin = $('#admin').val();
        var account = $('#account').val();
        var user = $('#user').val();
        goUrl(false, false, false, account, user);
        //location.replace("<?php echo base_url()?>information/information_purchase_user?account=" + account + "&user=" + user);
    });
    $('#user').click(function () {
        var accounts = $('#account').attr('checked');
        if (!accounts) {
            $('#account').val('2');
        } else {
            $('#account').val("");
        }
        var users = $('#user').attr('checked');
        if (!users) {
            $('#user').val('3');
        } else {
            $('#user').val("");
        }
        // var admin = $('#admin').val();
        var account = $('#account').val();
        var user = $('#user').val();
        goUrl(false, false, false, account, user);
        // location.replace("<?php echo base_url()?>information/information_purchase_user?account=" + account + "&user=" + user);
    });
    $('.calendar').on('click', function () {
        var myd = $('#mydatepicker').val(),
            myd2 = $('#mydatepicker2').val();
        $('#mydatepicker').attr('placeholder', myd);
        $('.mydatepicker2').val(myd);
        $('#mydatepicker2').attr('placeholder', myd2);
        var admin = $('#admin').val();
        var account = $('#account').val();
        var user = $('#user').val();
        console.log($('#mydatepicker').val());
        console.log($('#mydatepicker2').val());
        // window.location.search = jQuery.query.set("myd", myd).set("myd2", myd2);
        //location.replace("<?php //echo base_url()?>//information/information_purchase_user?ymd="+myd+"&ymd2="+myd2+"&admin="+admin+"&account="+account+"&user="+user);
    })

    function goUrl(s, e, n, a, u) {
        if (!s) {
            var s = $('#mydatepicker').attr('placeholder');
        }
        if (!e) {
            var e = $('#mydatepicker2').attr('placeholder');
        }
        if (!n) {
            var n = $('#username').val();
        }
        var accounts = $('#account').attr('checked');
        if (!accounts) {
            $('#account').val('2');
        } else {
            $('#account').val("");
        }
        var users = $('#user').attr('checked');
        if (!users) {
            $('#user').val('3');
        } else {
            $('#user').val("");
        }
        var a = $('#account').val();
        var u = $('#user').val();

        window.location.search = jQuery.query
            .set("mydatepicker", s)
            .set("mydatepicker2", e)
            .set("username", n)
            .set("account", a)
            .set("user", u)

    }


    $("#username").keydown(function (event) {
        event = event || window.event;
        if (event.keyCode == 13) {
            $("#data-form").submit();
        }
    });

    $("#data-form").on('submit', function (event) {
        event.stopPropagation();
        goUrl(false, false, $("#username").val());
        return false;
    })

</script>
</body>
</html>

